<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/favicon.png">
  <link rel="icon" type="image/png" href="/blog/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  
  <meta name="theme-color" content="#35495e">
  <meta name="description" content="小菜头的博客，主要记录学习笔记，包含：html,css,javascript,jQuery,vue等">
  <meta name="author" content="A-cai">
  <meta name="keywords" content="html,css,javascript,jQuery,vue">
  <title>vue原理解析observer模块 - A-cai的blog</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/blog/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/atom-one-dark.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/blog/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/blog/js/utils.js" ></script>
<meta name="generator" content="Hexo 4.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/blog/">&nbsp;<strong>A-cai的学习笔记</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/blog/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-06-26 14:04">
      2020年6月26日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.2k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      15
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
              <p class="note note-info">
                
                  本文最后更新于：2020年4月4日 下午
                
              </p>
            
            <article class="markdown-body">
              <h1 id="Vue原理解析之observer模块"><a href="#Vue原理解析之observer模块" class="headerlink" title="Vue原理解析之observer模块"></a>Vue原理解析之observer模块</h1><p><code>observer</code>是Vue核心中最重要的一个模块（个人认为），能够实现视图与数据的响应式更新，底层全凭<code>observer</code>的支持。</p>
<p><code>observer</code>模块在Vue项目中的代码位置是<code>src/core/observer</code>，模块共分为这几个部分：</p>
<ul>
<li><code>Observer</code>: 数据的观察者，让数据对象的读写操作都处于自己的监管之下</li>
<li><code>Watcher</code>: 数据的订阅者，数据的变化会通知到<code>Watcher</code>，然后由<code>Watcher</code>进行相应的操作，例如更新视图</li>
<li><code>Dep</code>: <code>Observer</code>与<code>Watcher</code>的纽带，当数据变化时，会被<code>Observer</code>观察到，然后由<code>Dep</code>通知到<code>Watcher</code></li>
</ul>
<p>示意图如下：</p>
<p><img src="https://segmentfault.com/img/bVJiAp?w=651&h=327" srcset="/blog/img/loading.gif" alt="clipboard.png"></p>
<h2 id="Observer"><a href="#Observer" class="headerlink" title="Observer"></a>Observer</h2><p><code>Observer</code>类定义在<code>src/core/observer/index.js</code>中，先来看一下<code>Observer</code>的构造函数</p>
<div class="hljs"><pre><code class="hljs cs">constructor (<span class="hljs-keyword">value</span>: any) &#123;
  <span class="hljs-keyword">this</span>.<span class="hljs-keyword">value</span> = <span class="hljs-keyword">value</span>
  <span class="hljs-keyword">this</span>.dep = <span class="hljs-keyword">new</span> Dep()
  <span class="hljs-keyword">this</span>.vmCount = <span class="hljs-number">0</span>
  def(<span class="hljs-keyword">value</span>, <span class="hljs-string">'__ob__'</span>, <span class="hljs-keyword">this</span>)
  <span class="hljs-keyword">if</span> (Array.isArray(<span class="hljs-keyword">value</span>)) &#123;
      <span class="hljs-keyword">const</span> augment = hasProto
      ? protoAugment
      : copyAugment
    augment(<span class="hljs-keyword">value</span>, arrayMethods, arrayKeys)
    <span class="hljs-keyword">this</span>.observeArray(<span class="hljs-keyword">value</span>)
  &#125; <span class="hljs-keyword">else</span> &#123;
    <span class="hljs-keyword">this</span>.walk(<span class="hljs-keyword">value</span>)
  &#125;
&#125;</code></pre></div>

<p><code>value</code>是需要被观察的数据对象，在构造函数中，会给<code>value</code>增加<code>__ob__</code>属性，作为数据已经被<code>Observer</code>观察的标志。如果<code>value</code>是数组，就使用<code>observeArray</code>遍历<code>value</code>，对<code>value</code>中每一个元素调用<code>observe</code>分别进行观察。如果<code>value</code>是对象，则使用<code>walk</code>遍历<code>value</code>上每个key，对每个key调用<code>defineReactive</code>来获得该key的<code>set/get</code>控制权。</p>
<p>解释下上面用到的几个函数的功能：</p>
<ul>
<li><code>observeArray</code>: 遍历数组，对数组的每个元素调用<code>observe</code></li>
<li><code>observe</code>: 检查对象上是否有<code>__ob__</code>属性，如果存在，则表明该对象已经处于<code>Observer</code>的观察中，如果不存在，则<code>new Observer</code>来观察对象（其实还有一些判断逻辑，为了便于理解就不赘述了）</li>
<li><code>walk</code>: 遍历对象的每个key，对对象上每个key的数据调用<code>defineReactive</code></li>
<li><code>defineReactive</code>: 通过<code>Object.defineProperty</code>设置对象的key属性，使得能够捕获到该属性值的<code>set/get</code>动作。一般是由<code>Watcher</code>的实例对象进行<code>get</code>操作，此时<code>Watcher</code>的实例对象将被自动添加到<code>Dep</code>实例的依赖数组中，在外部操作触发了<code>set</code>时，将通过<code>Dep</code>实例的<code>notify</code>来通知所有依赖的<code>watcher</code>进行更新。</li>
</ul>
<p>如果不太理解上面的文字描述可以看一下图：</p>
<p><img src="https://segmentfault.com/img/bVJiJC?w=844&h=337" srcset="/blog/img/loading.gif" alt="clipboard.png"></p>
<h2 id="Dep"><a href="#Dep" class="headerlink" title="Dep"></a>Dep</h2><p><code>Dep</code>是<code>Observer</code>与<code>Watcher</code>之间的纽带，也可以认为<code>Dep</code>是服务于<code>Observer</code>的订阅系统。<code>Watcher</code>订阅某个<code>Observer</code>的<code>Dep</code>，当<code>Observer</code>观察的数据发生变化时，通过<code>Dep</code>通知各个已经订阅的<code>Watcher</code>。</p>
<p><code>Dep</code>提供了几个接口：</p>
<ul>
<li><code>addSub</code>: 接收的参数为<code>Watcher</code>实例，并把<code>Watcher</code>实例存入记录依赖的数组中</li>
<li><code>removeSub</code>: 与<code>addSub</code>对应，作用是将<code>Watcher</code>实例从记录依赖的数组中移除</li>
<li><code>depend</code>: <code>Dep.target</code>上存放这当前需要操作的<code>Watcher</code>实例，调用<code>depend</code>会调用该<code>Watcher</code>实例的<code>addDep</code>方法，<code>addDep</code>的功能可以看下面对<code>Watcher</code>的介绍</li>
<li><code>notify</code>: 通知依赖数组中所有的<code>watcher</code>进行更新操作</li>
</ul>
<h2 id="Watcher"><a href="#Watcher" class="headerlink" title="Watcher"></a>Watcher</h2><p><code>Watcher</code>是用来订阅数据的变化的并执行相应操作（例如更新视图）的。<code>Watcher</code>的构造器函数定义如下：</p>
<div class="hljs"><pre><code class="hljs kotlin"><span class="hljs-keyword">constructor</span> (vm, expOrFn, cb, options) &#123;
  <span class="hljs-keyword">this</span>.vm = vm
  vm._watchers.push(<span class="hljs-keyword">this</span>)
  <span class="hljs-comment">// options</span>
  <span class="hljs-keyword">if</span> (options) &#123;
    <span class="hljs-keyword">this</span>.deep = !!options.deep
    <span class="hljs-keyword">this</span>.user = !!options.user
    <span class="hljs-keyword">this</span>.lazy = !!options.lazy
    <span class="hljs-keyword">this</span>.sync = !!options.sync
  &#125; <span class="hljs-keyword">else</span> &#123;
    <span class="hljs-keyword">this</span>.deep = <span class="hljs-keyword">this</span>.user = <span class="hljs-keyword">this</span>.lazy = <span class="hljs-keyword">this</span>.sync = <span class="hljs-literal">false</span>
  &#125;
  <span class="hljs-keyword">this</span>.cb = cb
  <span class="hljs-keyword">this</span>.id = ++uid <span class="hljs-comment">// uid for batching</span>
  <span class="hljs-keyword">this</span>.active = <span class="hljs-literal">true</span>
  <span class="hljs-keyword">this</span>.dirty = <span class="hljs-keyword">this</span>.lazy <span class="hljs-comment">// for lazy watchers</span>
  <span class="hljs-keyword">this</span>.deps = []
  <span class="hljs-keyword">this</span>.newDeps = []
  <span class="hljs-keyword">this</span>.depIds = new Set()
  <span class="hljs-keyword">this</span>.newDepIds = new Set()
  <span class="hljs-keyword">this</span>.expression = process.env.NODE_ENV !== <span class="hljs-string">'production'</span>
    ? expOrFn.toString()
    : <span class="hljs-string">''</span>
  <span class="hljs-keyword">if</span> (typeof expOrFn === <span class="hljs-string">'function'</span>) &#123;
    <span class="hljs-keyword">this</span>.getter = expOrFn
  &#125; <span class="hljs-keyword">else</span> &#123;
    <span class="hljs-keyword">this</span>.getter = parsePath(expOrFn)
    <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.getter) &#123;
      <span class="hljs-keyword">this</span>.getter = function () &#123;&#125;
      process.env.NODE_ENV !== <span class="hljs-string">'production'</span> &amp;&amp; warn(
        `Failed watching path: <span class="hljs-string">"<span class="hljs-subst">$&#123;expOrFn&#125;</span>"</span> ` +
        <span class="hljs-string">'Watcher only accepts simple dot-delimited paths. '</span> +
        <span class="hljs-string">'For full control, use a function instead.'</span>,
        vm
      )
    &#125;
  &#125;
  <span class="hljs-keyword">this</span>.value = <span class="hljs-keyword">this</span>.lazy
    ? undefined
    : <span class="hljs-keyword">this</span>.<span class="hljs-keyword">get</span>()
&#125;</code></pre></div>

<p>参数中，<code>vm</code>表示组件实例，<code>expOrFn</code>表示要订阅的数据字段（字符串表示，例如<code>a.b.c</code>）或是一个要执行的函数，<code>cb</code>表示watcher运行后的回调函数，<code>options</code>是选项对象，包含<code>deep</code>、<code>user</code>、<code>lazy</code>等配置。</p>
<p><code>watcher</code>实例上有这些方法：</p>
<ul>
<li><code>get</code>: 将<code>Dep.target</code>设置为当前<code>watcher</code>实例，在内部调用<code>this.getter</code>，如果此时某个被<code>Observer</code>观察的数据对象被取值了，那么当前<code>watcher</code>实例将会自动订阅数据对象的<code>Dep</code>实例</li>
<li><code>addDep</code>: 接收参数<code>dep</code>(Dep实例)，让当前<code>watcher</code>订阅<code>dep</code></li>
<li><code>cleanupDeps</code>: 清除<code>newDepIds</code>和<code>newDep</code>上记录的对dep的订阅信息</li>
<li><code>update</code>: 立刻运行<code>watcher</code>或者将<code>watcher</code>加入队列中等待统一flush</li>
<li><code>run</code>: 运行<code>watcher</code>，调用<code>this.get()</code>求值，然后触发回调</li>
<li><code>evaluate</code>: 调用<code>this.get()</code>求值</li>
<li><code>depend</code>: 遍历<code>this.deps</code>，让当前<code>watcher</code>实例订阅所有<code>dep</code></li>
<li><code>teardown</code>: 去除当前<code>watcher</code>实例所有的订阅</li>
</ul>
<h2 id="Array-methods"><a href="#Array-methods" class="headerlink" title="Array methods"></a>Array methods</h2><p>在<code>src/core/observer/array.js</code>中，Vue框架对数组的<code>push</code>、<code>pop</code>、<code>shift</code>、<code>unshift</code>、<code>sort</code>、<code>splice</code>、<code>reverse</code>方法进行了改造，在调用数组的这些方法时，自动触发<code>dep.notify()</code>，解决了调用这些函数改变数组后无法触发更新的问题。在Vue的官方文档中对这个也有说明：<a href="http://cn.vuejs.org/v2/guide/list.html#" target="_blank" rel="noopener">http://cn.vuejs.org/v2/guide/list.html#变异方法</a></p>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/blog/2020/06/26/Vue%E6%A1%86%E6%9E%B6%E4%B8%AD%E4%BD%BF%E7%94%A8nextTick%E5%8E%9F%E7%90%86/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Vue框架中使用nextTick原理</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/blog/2020/06/26/vue%E5%A6%82%E4%BD%95%E4%BC%98%E5%8C%96%E9%A6%96%E9%A1%B5%E5%8A%A0%E8%BD%BD%E9%80%9F%E5%BA%A6/">
                        <span class="hidden-mobile">vue如何优化首页加载速度</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
              <!-- Comments -->
              <div class="comments" id="comments">
                
                

              </div>
            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    

    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/debouncer.js" ></script>
<script  src="/blog/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/blog/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/blog/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "vue原理解析observer模块&nbsp;",
      ],
      cursorChar: "|",
      typeSpeed: 70,
      loop: true,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/blog/js/local-search.js" ></script>
  <script>
    var path = "/blog/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  













</body>
</html>
